package br.edu.ifpb.loginaplicacao;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class UriActivity extends Activity implements OnClickListener{

	@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.uri_layout);
		
		Intent intent = getIntent();
		Bundle params = intent.getExtras();
		TextView textView = (TextView) findViewById(R.id.bemVindoTextView);
		
		if (params != null) {
			String nome = params.getString("nome");
			textView.setText("Bem vindo! " + nome);
		}
		
		
		Button button = (Button) findViewById(R.id.carregarButton);
		button.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		EditText endereco = (EditText) findViewById(R.id.uriEditText);
		
		Uri url = Uri.parse(endereco.getText().toString());

		//INTENT que abre o navegador.
		Intent intencaoDeAbrirNavegador = new Intent(Intent.ACTION_VIEW, url);

		//Enviando a mensagem para o sistema operacional abrir o Browser
		startActivity(intencaoDeAbrirNavegador);		
	}
}
